/*
 * Board.java
 *
 * Created on 05. Juni 2007, 02:44
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sbc.repos;

import sbc.util.*;
import java.util.*;
import org.xvsm.api.core.*;
import corso.lang.*;

/**
 *
 * @author mustermark
 */
public class Board extends Module {
    
    private String uid;
    private Type type = Module.Type.SENSOR;
    
    
    /** Creates a new instance of Board */
    /*protected Board(String id) {
        super(Module.Type.BOARD);
        uid = id;
    }*/
    public Board() {
    
    }
    
    public Board(String id) {
        //super(Module.Type.BOARD);
        uid = id;
    }
    public Board(CorsoVarOid oid) {
        super(oid);
    }
    
    public String getUID() {
        return uid;
    }
    public Type getType() { return type; }
    public Tuple asTuple() {
        Tuple boardTuple = new Tuple();
        boardTuple.addEntry(Entry.Factory.newInstance(ValueTypes.STRING_UTF8, type.toString()));
        boardTuple.addEntry(Entry.Factory.newInstance(ValueTypes.STRING_UTF8, uid));
        return boardTuple;
        
    }
    
    public void write (CorsoData data) throws CorsoDataException {
        data.putStructTag (getType().toString(), 1);
        data.putString(uid);
        //data.p.putShareable (towerOid);
        //data.putShareable (landebahnenOid);
    }
    public void read (CorsoData data) throws CorsoDataException {
        StringBuffer structName = new StringBuffer ();
        int arity = data.getStructTag (structName);
        if (arity != 1)
            throw new CorsoDataException ();
        
        if (!structName.toString ().equals (getType().toString())) {
            throw new CorsoDataException ();
        }
        uid = data.getString();
        
    }
    
    
}
